//package com.tanhua.recommend.listener;
//
//import com.alibaba.fastjson.JSON;
//import com.tanhua.domain.mongo.Publish;
//import com.tanhua.domain.mongo.PublishScore;
//import com.tanhua.recommend.handler.PublishScoreHandler;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.bson.types.ObjectId;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Map;
//
//@Component
//@RocketMQMessageListener(topic = "tanhua-quanzi", consumerGroup = "tanhua-quanzi-consumer")
//public class PublishScoreListener2 implements RocketMQListener<String> {
//
//    @Autowired
//    private MongoTemplate mongoTemplate;
//
//    @Autowired
//    private List<PublishScoreHandler> handlerList;
//
//    @Override
//    public void onMessage(String message) {
//        // 1.解析消息
//        Map<String, Object> map = JSON.parseObject(message, Map.class);
//        Integer type = Integer.valueOf(map.get("type").toString());
//        Long userId = Long.valueOf(map.get("userId").toString());
//        String publishId = (String) map.get("publishId");
//        Long pid = Long.valueOf(map.get("pid").toString());
//
//        // 2.创建评分数据对象
//        PublishScore publishScore = new PublishScore();
//        publishScore.setUserId(userId);
//        publishScore.setPublishId(pid);
//        publishScore.setDate(System.currentTimeMillis());
//
//        Publish publish = mongoTemplate.findById(new ObjectId(publishId), Publish.class);
//
//        // 3.计算得分
//        // type 1-发动态，2-浏览动态， 3-点赞， 4-喜欢， 5-评论，6-取消点赞，7-取消喜欢
//        for (PublishScoreHandler publishScoreHandler : handlerList) {
//            // 如果判断成立，代表由某处理器处理
//            if (publishScoreHandler.shouldHandle(type)) {
//                publishScoreHandler.handle(publish);
//            }
//        }
//
//        // 保存评分数据到mongoDB
//        mongoTemplate.save(publishScore);
//
//    }
//
//
//}
